package com.yami.shop.admin.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.ActivityPro;
import com.yami.shop.bean.model.Agent;
import com.yami.shop.bean.model.Product;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.ActivityService;
import com.yami.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @Autowired
    private ProductService productService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<ActivityPro>> page(ActivityPro activityPro, PageParam<ActivityPro> page){
      //  IPage<ActivityPro> agentList = activityService.page(page,new LambdaQueryWrapper<ActivityPro>()
      //          .orderByDesc(ActivityPro::getActivityId));
        Long shopId = SecurityUtils.getSysUser().getShopId();
        IPage<ActivityPro> activityProIPage = activityService.getActivityProdByShopId(page,shopId);
        return ResponseEntity.ok(activityProIPage);
    }

    /**
     * 新增保存
     */
    @PostMapping("/saveActivityPro")
    public ResponseEntity<String> saveActivityPro(@RequestBody ActivityPro activityPro){
        String result =activityService.saveActivityPro(activityPro);
        return  ResponseEntity.ok(result);
    }

    /**
     * 获取商品列表
     */
    @GetMapping("/getActivityPro")
    public ResponseEntity<List<Product>> getActivityPro(){
        Long shopId = SecurityUtils.getSysUser().getShopId();
        List<Product>  prodList = productService.getActivityPro(shopId);
       return  ResponseEntity.ok(prodList);
    }

    /**
     * 修改活动商品内容
     */
    @PostMapping("/updateActivityPro")
    public ResponseEntity<String> updateActivityPro(@RequestBody ActivityPro activityPro){
        String result =  activityService.updateActivity(activityPro);
        return  ResponseEntity.ok(result);
    }

    /**
     * 删除活动
     */
    @PostMapping("/deleteActivity")
    public ResponseEntity<String> deleteActivity(@RequestBody ActivityPro activityPro){
        String result ="success";
        //删除活动,修改产品有关属性
        activityService.deleteActivity(activityPro);
        return  ResponseEntity.ok(result);
    }

}
